import { Injectable } from '@angular/core';
import { ApolloQueryResult, FetchResult } from '@apollo/client/core';
import { Apollo, gql, QueryRef } from 'apollo-angular';
import { Observable } from 'rxjs';
import { CollectionNamesServiceApi,
CollectionNamesService_addToCollectionsResult,
CollectionNamesService_addToCollectionsVariables,
CollectionNamesService_myCollectionsResult,
CollectionNamesService_myCollectionsVariables,
CollectionNamesService_listResult,
CollectionNamesService_listVariables,
CollectionNamesService_totalCountResult,
CollectionNamesService_searchResult,
CollectionNamesService_searchVariables,
CollectionNamesService_loadAllResult,
CollectionNamesService_getByIdResult,
CollectionNamesService_getByIdVariables,
CollectionNamesService_saveResult,
CollectionNamesService_saveVariables,
CollectionNamesService_removeByIdResult,
CollectionNamesService_removeByIdVariables,
CollectionNamesService_removeByIdListResult,
CollectionNamesService_removeByIdListVariables,
CollectionNamesResultInfo, CollectionNamesPageInfo,
CollectionNamesConnection,
CollectionNamesPackage,
CollectionNamesOrderBy,
CollectionNamesMutationInfo,
CollectionNamesStringFilter,
CollectionNamesNumberFilter,
CollectionNamesBooleanFilter,
collectionNamesServiceQuery,
collectionNamesServiceMutation,
CollectionNamesServiceQueryOptions,
CollectionNamesStore,
CollectionNamesView,
CollectionNamesInput,
CollectionNamesFilter,
CollectionNamesErrorBody} from '../model/collection_names_service.model';

/************************************************************************
 * 收藏资源
 */
@Injectable({
    providedIn: 'root'
})
export class CollectionNamesService implements CollectionNamesServiceApi {

        private addToCollectionsGql:string;
        private myCollectionsGql:string;
        private listGql:string;
        private totalCountGql:string;
        private searchGql:string;
        private searchObjectRef: QueryRef<CollectionNamesService_searchResult>;
        private loadAllGql:string;
        private getByIdGql:string;

    constructor(private apollo: Apollo) {
        this.addToCollectionsGql=`query nars_collectionNamesService_addToCollections($path: String!){${collectionNamesServiceQuery.collectionNamesService_addToCollections}}`;
        this.myCollectionsGql=`query nars_collectionNamesService_myCollections($first: Int!,$offset: Float!){${collectionNamesServiceQuery.collectionNamesService_myCollections}}`;
        this.listGql=`query nars_collectionNamesService_list($filter: CollectionNamesFilter!,$orderBy: OrderBy){${collectionNamesServiceQuery.collectionNamesService_list}}`;
        this.totalCountGql=`query nars_collectionNamesService_totalCount{${collectionNamesServiceQuery.collectionNamesService_totalCount}}`;
        this.searchGql=`query nars_collectionNamesService_search($first: Int!,$offset: Float!,$filter: CollectionNamesFilter!,$orderBy: OrderBy){${collectionNamesServiceQuery.collectionNamesService_search}}`;
        this.searchObjectRef = apollo.watchQuery<CollectionNamesService_searchResult>({ query: gql`${this.searchGql}`, fetchPolicy:'cache-first' });
        this.loadAllGql=`query nars_collectionNamesService_loadAll{${collectionNamesServiceQuery.collectionNamesService_loadAll}}`;
        this.getByIdGql=`query nars_collectionNamesService_getById($id: String!){${collectionNamesServiceQuery.collectionNamesService_getById}}`;
    }
    /**
     * 添加到收藏
     */
    addToCollections(variables: CollectionNamesService_addToCollectionsVariables, options:CollectionNamesServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<CollectionNamesService_addToCollectionsResult>> {
            return this.apollo.query({ query: gql`${this.addToCollectionsGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 我的收藏
     */
    myCollections(variables: CollectionNamesService_myCollectionsVariables, options:CollectionNamesServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<CollectionNamesService_myCollectionsResult>> {
            return this.apollo.query({ query: gql`${this.myCollectionsGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 分页查询
     */
    list(variables: CollectionNamesService_listVariables, options:CollectionNamesServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<CollectionNamesService_listResult>> {
            return this.apollo.query({ query: gql`${this.listGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 统计库中所有对象的数据量
     */
    totalCount(options:CollectionNamesServiceQueryOptions = { cachePolicy: 'no-cache', more: false }): Observable<ApolloQueryResult<CollectionNamesService_totalCountResult>> {
            return this.apollo.query({ query: gql`${this.totalCountGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 游标查询
     */
    search(variables: CollectionNamesService_searchVariables, options:CollectionNamesServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<CollectionNamesService_searchResult>> {
        this.searchObjectRef.setVariables(variables);
        if(options.more){
            this.searchObjectRef.fetchMore({variables});
        }
        return this.searchObjectRef.valueChanges;
    }
    /**
     * 获取库中所有数据，数据量大时请谨慎使用
     */
    loadAll(options:CollectionNamesServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<CollectionNamesService_loadAllResult>> {
            return this.apollo.query({ query: gql`${this.loadAllGql}`,fetchPolicy:options.cachePolicy});
    }
    /**
     * 获取一个对象
     */
    getById(variables: CollectionNamesService_getByIdVariables, options:CollectionNamesServiceQueryOptions = { cachePolicy: 'cache-first', more: false }): Observable<ApolloQueryResult<CollectionNamesService_getByIdResult>> {
            return this.apollo.query({ query: gql`${this.getByIdGql}`,variables ,fetchPolicy:options.cachePolicy});
    }
    /**
     * 保存对象
     */
    save(variables: CollectionNamesService_saveVariables): Observable<FetchResult<CollectionNamesService_saveResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_collectionNamesService_save($entity: CollectionNamesInput!){${collectionNamesServiceMutation.collectionNamesService_save}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一个对象
     */
    removeById(variables: CollectionNamesService_removeByIdVariables): Observable<FetchResult<CollectionNamesService_removeByIdResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_collectionNamesService_removeById($id: String!){${collectionNamesServiceMutation.collectionNamesService_removeById}}`, variables,fetchPolicy:'no-cache'});
    }
    /**
     * 删除一批对象
     */
    removeByIdList(variables: CollectionNamesService_removeByIdListVariables): Observable<FetchResult<CollectionNamesService_removeByIdListResult>>{
        return this.apollo.mutate({mutation: gql`mutation nars_collectionNamesService_removeByIdList($ids: [String]!){${collectionNamesServiceMutation.collectionNamesService_removeByIdList}}`, variables,fetchPolicy:'no-cache'});
    }









}
